package com.dkd.tbSku.controller;


import com.dkd.common.core.controller.BaseController;
import com.dkd.common.core.domain.AjaxResult;
import com.dkd.common.core.domain.R;
import com.dkd.common.core.page.TableDataInfo;
import com.dkd.tbSku.domain.TbSku;
import com.dkd.tbSku.domain.TbSkuDto;
import com.dkd.tbSku.service.ITbSkuService;
import com.dkd.testUser.domain.TestUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 商品表 前端控制器
 * </p>
 *
 * @author zwy
 * @since 2025-05-01
 */
@Api(tags = "商品管理")
@RestController
@RequestMapping("/tbSku")
public class TbSkuController extends BaseController {
    @Autowired
    private ITbSkuService service;

    /**
     * 查询商品列表
     */
    @ApiOperation("查询商品列表")
    @PreAuthorize("@ss.hasPermi('tbSku:sku:list')")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody TbSkuDto skuQuery) {
        startPage();
        return getDataTable(service.selectList(skuQuery));
    }

    /**
     * 详情
     *
     * @param id
     * @return 写入了redis
     */
    @ApiOperation("查询商品详情")
    @PreAuthorize("@ss.hasPermi('tbSku:sku:query')")
    @GetMapping(value = "/{id}")
    public R<TbSku> getInfo(@PathVariable("id") Integer id) {
        return R.ok(service.selectById(id));
    }

    /**
     * 新增用户以及商品
     */
    @ApiOperation("新增商品")
    @PreAuthorize("@ss.hasPermi('tbSku:sku:add')")
    @PostMapping
    public AjaxResult getInfo(@RequestBody TbSku tbSku) {
        return AjaxResult.success(service.insertTbSku(tbSku));
    }

    /**
     * 删除用户
     */
    @ApiOperation("批量删除商品")
    @PreAuthorize("@ss.hasPermi('tbSku:sku:remove')")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(service.delecteTbSkus(ids));
    }

    /**
     * 修改
     */
    @ApiOperation("修改商品")
    @PreAuthorize("@ss.hasPermi('tbSku:sku:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody TbSku tbSku) {
        return toAjax(service.updateTbSku(tbSku));
    }

}
